types(ModalSubmitInteraction): make attachments optional#11363
types(ModalSubmitInteraction): make attachments optional#11363rahuld109 wants to merge 2 commits intodiscordjs:mainfrom
Conversation
The attachments field can be undefined when a user doesn't upload a file in an optional FileUpload component, but the types didn't reflect this possibility, causing runtime errors. close discordjs#11359
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)packages/discord.js/typings/index.d.ts (1)
🔇 Additional comments (1)
Comment |
|
Is there a reason we don't just always create a collection? Thoughts? |
|
If we receive an empty array, we should make an empty collection. |
|
Just checking - would you like me to switch to the alternate approach (always creating an empty collection at runtime)? Let me know and I can make that change. |
If Discord sends an empty array, we should be setting |
Jiralite
left a comment
There was a problem hiding this comment.
I have just verified this behaviour:
{
"type": 18,
"id": 9,
"component": {
"values": [],
"type": 19,
"id": 10,
"custom_id": "164"
}
}An empty array is sent for values. The types are fine, it's JavaScript that needs to be fixed–an empty collection should be used.
Summary
Makes
FileUploadModalData.attachmentsoptional to match runtime behavior.Problem
When a modal has an optional
FileUploadcomponent and the user doesn't upload a file,component.attachmentsisundefinedat runtime. However, the TypeScript types marked it as required, causing no compile-time warning but runtime errors when accessing the property.Solution
Add
?to theattachmentsfield inFileUploadModalDatainterface:Closes #11359